package com.imooc.consumer.filter;

import com.utils.Const;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/5/22-2024
 * @Description: 这里用一句话描述这个类的作用
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("producer");
        producer.setNamesrvAddr(Const.NAME_SERVER_SINGLE);
        producer.setSendMsgTimeout(5000);
        producer.start();

        String[] tags = new String[]{"TagA", "TagB", "TagC"};

        for (int i = 0; i < 10; i++) {
            Message message = new Message("test", tags[i % tags.length], "key", "message".getBytes());
            message.putUserProperty("a", String.valueOf(i));  //设置用户属性
            //message.setDelayTimeLevel();
            SendResult sendResult = producer.send(message);
        }
        System.out.println("消息发送成功!!!");
    }
}